package com.yxt.ui;

import com.yxt.common.sys.CommConstant;
import com.yxt.common.ui.ActivityStackControlUtil;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;

public class WeatherDisplayActivity extends Activity {
	private TextView lblTitle;
	private WebView wvWeather;
	private static final int TQYB_MENU = Menu.FIRST+1;
	private static final int SZYB_MENU = Menu.FIRST + 2;
	private static final int WQPA_MENU = Menu.FIRST + 3;
	private static final int DLTU_MENU = Menu.FIRST + 4;	

	private void initComponent() {
		Button btnBackHome = (Button) findViewById(R.id.btnBackHome);
		lblTitle = (TextView) findViewById(R.id.lblTitle);
		wvWeather = (WebView) findViewById(R.id.wvWeather);
		btnBackHome.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
			}
		});
		modifyTitle(getString(R.string.menu_tqyb),CommConstant.Weather.DEFAULT_WEATHER);
	}

	private void modifyTitle(String title, String url) {
		lblTitle.setText(title);
		wvWeather.loadUrl(url);
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.weather); // 软件activity的布局
		ActivityStackControlUtil.add(this);
		initComponent();
	}
	
	/**
	 * 创建底部菜单
	 * */
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, TQYB_MENU, 1, R.string.menu_tqyb);
		menu.add(0, SZYB_MENU, 2, R.string.menu_szyb);
		menu.add(0, WQPA_MENU, 3, R.string.menu_phatu);
		menu.add(0, DLTU_MENU, 4, R.string.menu_dltu);
		return super.onCreateOptionsMenu(menu);
	}
	
	/**
	 * 点击底部菜单项时的处理
	 */
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case TQYB_MENU:
				modifyTitle(getString(R.string.menu_tqyb),CommConstant.Weather.DEFAULT_WEATHER);	
				return true;
			case SZYB_MENU:
				modifyTitle(getString(R.string.menu_szyb),CommConstant.Weather.DEFAULT_QXXX);	
				return true;
			case WQPA_MENU:
				modifyTitle(getString(R.string.menu_phatu),CommConstant.Weather.DEFAULT_WEATHER);	
				return true;
			case DLTU_MENU:
				modifyTitle(getString(R.string.menu_dltu),CommConstant.Weather.DEFAULT_QXXX);	
				return true;
		}
		return super.onOptionsItemSelected(item);
	}

	protected void onDestroy() {
		super.onDestroy();
        ActivityStackControlUtil.remove(this);
	}
}